<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <base id="base" href="${s.basePath}">
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="${s.basePath}/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${s.basePath}/easyui/themes/icon.css">
    <script type="text/javascript" src="${s.basePath}/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="${s.basePath}/easyui/jquery.easyui.min.js"></script>
</head>
<style>
    body {
        /*background: #FAFAFA;*/
    }
</style>
<body>
<div>
    <div style="margin: 200px auto;width: 400px;">
        <div id="p" class="easyui-panel" title="登录"
             style="width:400px;height:255px;padding:10px;background:#fafafa;"
             data-options="iconCls:'icon-save'">

            <form id="form" method="post">
                <h2 align="center">登录系统</h2>
                <div>
                    <input class="easyui-textbox easyui-validatebox" iconWidth="28" id="username" name="username"
                           data-options="iconCls:'icon-man',validType:'minLength[5]',required:true" style="width:100%;"
                           prompt="Username"><br><br>
                </div>
                <div>
                    <input class="easyui-passwordbox" prompt="Password" id="password" name="password" iconWidth="28"
                           style="width:100%;" data-options="required:true,validType:'pwd'"><br><br>
                </div>
                <div align="right">
                    <a href="javascript:;;" class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
                       id="form_sub">提交</a>
                    <a href="javascript:;;" class="easyui-linkbutton" data-options="iconCls:'icon-reload'"
                       id="form_ret">重置</a>
                </div>
            </form>
        </div>
    </div>
</div>
</div>
</body>
<#if Session.reLogin?exists>
    <div id="reLogin" style="display: none">${Session.reLogin.reLoginIP?string}</div>
</#if>
<script type="text/javascript">

    var basePath = $("#base").attr("href");
    function resetReloginStat() {
        $.post(basePath+"/resetReloginStat",{"reset":true},function (data) {
            if (data.result)
                console.log("reset relogin stat");
        })
    }

    $(function () {
        var reLoginIP = $("#reLogin").text();
        if (reLoginIP != null && reLoginIP.length > 0) {
            console.log(reLoginIP);
            $.messager.alert("warn", "您的账号在别处登录，IP = " + reLoginIP + "<br>您被迫下线，请注意账号安全！！！");
            resetReloginStat();
        }
        // console.log(basePath);
        $("#form_sub").on('click', function () {
            $.messager.progress();
            $('#form').form('submit', {
                url: basePath + "/login.do",
                onSubmit: function () {
                    // do some check
                    // return false to prevent submit;
                    var isValid = $(this).form('validate');
                    if (!isValid) {
                        $.messager.progress('close');
                    }
                    return isValid;
                },
                success: function (data) {
                    var data = eval('(' + data + ')');
                    if (data.result) {
                        $.messager.progress('close');
                        window.location.href = basePath + '/tohome';
                    } else {
                        $.messager.progress('close');
                        $.messager.alert("系统信息", data.msg);
                    }
                }
            });
        })

        $(document).keydown(function (event) {
            if (event.keyCode == 13) (
                    $("#form_sub").click()
            )
        })
        $.extend($.fn.validatebox.defaults.rules, {
            minLength: {
                validator: function (value, param) {
                    return value.length >= param[0];
                },
                message: 'Please enter at least {0} characters.'
            }
        });

        var regEn = /[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im,
                regCn = /[·！#￥（——）：；“”‘、，|《。》？、【】[\]]/im;
        $.extend($.fn.validatebox.defaults.rules, {
            pwd: {
                validator: function (value) {
                    if (!regEn.test(value) && !regCn.test(value)) {
                        return true;
                    } else
                        return false;
                },
                message: '不可以输入特殊字符.'
            }
        });
    })
</script>
</html>